<?php

namespace App\Console\Commands\Fy;

use App\Imports\Fy\FyRegionBankImport;
use App\Imports\Fy\FyRegionImport;
use App\Models\Fy\FyRegionBankModel;
use Illuminate\Console\Command;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Facades\Excel;

class GenerateRegionBank extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'fy:generateRegionBank';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '富有：生成富有省市区银行';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        ini_set('memory_limit', '6G');

        FyRegionBankModel::query()->chunkById(1000, function (Collection $fyRegionBankGroup) {
            $fyRegionBankGroup->each(function (FyRegionBankModel $fyRegionBankModel) {
                $fyRegionBankModel->bankTypeCode = trim($fyRegionBankModel->bankTypeCode);
                $fyRegionBankModel->name         = trim($fyRegionBankModel->name);
                $fyRegionBankModel->save();
            });
        });


//        $filePath = downloadFile(
//            "https://open.fuioupay.com/downLoad.do?fileId=36c81f4d-dbfb-4c2e-89fb-c5bbe6ec8c1a",
//            "fy",
//            "fyRegionBank",
//            "xlsx"
//        );
//45796//110842
//        $this->getOutput()->info($filePath);
//        $filePath = "/www/tiger-api/storage/fy/fyRegionBank.xlsx";
//        Excel::import(new FyRegionBankImport(), $filePath);
        return 0;
    }
}
